﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;

namespace SmartMathLibrary.Management.Pipe
{
    /// <summary>
    /// The pipevalues allows to set the variables or values of a pipe.
    /// </summary>
    [Serializable]
    public class PipeValue : IPipeValue
    {
        /// <summary>
        /// The name of the pipevalue object.
        /// </summary>
        private String name;

        /// <summary>
        /// The value of the current pipevalue object.
        /// </summary>
        private Object value;

        /// <summary>
        /// Initializes a new instance of the <see cref="PipeValue"/> class.
        /// </summary>
        /// <param name="name">The name of the pipevalue object.</param>
        /// <param name="value">The value of the pipevalue object.</param>
        public PipeValue(String name, Object value)
        {
            if (name == (string) null)
            {
                throw new ArgumentNullException("name");
            }

            this.name = name;
            this.value = value;
        }

        /// <summary>
        /// Gets or sets the name of the pipevalue object.
        /// </summary>
        /// <value>The name of the pipevalue object.</value>
        public String Name
        {
            get { return name; }
            set { name = value; }
        }

        /// <summary>
        /// Gets or sets the value of the current pipevalue object.
        /// </summary>
        /// <value>The value of the current pipevalue object.</value>
        public Object Value
        {
            get { return this.value; }
            set { this.value = value; }
        }

        /// <summary>
        /// Determines whether the specified <see cref="T:System.Object"/> is equal to the current <see cref="T:System.Object"/>.
        /// </summary>
        /// <param name="obj">The <see cref="T:System.Object"/> to compare with the current <see cref="T:System.Object"/>.</param>
        /// <returns>
        /// true if the specified <see cref="T:System.Object"/> is equal to the current <see cref="T:System.Object"/>; otherwise, false.
        /// </returns>
        /// <exception cref="T:System.NullReferenceException">The <paramref name="obj"/> parameter is null.</exception>
        public override bool Equals(object obj)
        {
            if (obj is PipeValue)
            {
                if (((PipeValue) obj).Name == (string) null)
                {
                    throw new ArgumentNullException("obj");
                }

                return ((((PipeValue) obj).Name.Equals(this.name))
                        && (((PipeValue) obj).Value.Equals(this.value)));
            }

            return false;
        }

        /// <summary>
        /// Serves as a hash function for a particular type.
        /// </summary>
        /// <returns>
        /// A hash code for the current <see cref="T:System.Object"/>.
        /// </returns>
        public override int GetHashCode()
        {
            return base.GetHashCode();
        }

        /// <summary>
        /// Returns a <see cref="T:System.String"/> that represents the current <see cref="T:System.Object"/>.
        /// </summary>
        /// <returns>
        /// A <see cref="T:System.String"/> that represents the current <see cref="T:System.Object"/>.
        /// </returns>
        public override string ToString()
        {
            return this.name.ToString();
        }
    }
}